<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('讨论区')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="role-form">
					<div class="select-list">
						<ul>
							<li>
								工号：<input type="text" name="userId"/>
							</li>
							<li>
								姓名：<input type="text" name="author"/>
							</li>
							<li>
								主题：<input type="text" name="talkCenter"/>
							</li>
							<li>
								审核状态：<select name="auditState" id="auditState" style="width:140px">
								<option value="0">无</option>
								<option value="1">待审核</option>
								<option value="2">通过</option>
								<option value="3">不通过</option>
								</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>

			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success multiple disabled" onclick="agreeAll()" shiro:hasPermission="system:talkaudit:agree">
					<i class="fa fa-plus"></i> 通过
				</a>
				<a class="btn btn-danger multiple disabled" onclick="rejectAll()" shiro:hasPermission="system:talkaudit:reject">
					<i class="fa fa-remove"></i> 拒绝
				</a>
			</div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var agreeFlag = [[${@permission.hasPermi('system:talkaudit:agree')}]];
		var rejectFlag = [[${@permission.hasPermi('system:talkaudit:reject')}]];
		var seeFlag = [[${@permission.hasPermi('system:talkaudit:see')}]];
		var prefix = ctx + "sau/talkaudit";
		

		$(function() {
		    var options = {
		        url: prefix + "/selectAllTalk",
		        updateUrl: prefix + "/see/{id}",
				agreeUrl: prefix + "/agree",
				rejectUrl: prefix + "/reject",
		        sortName: "talkId",
		        modalName: "帖子",
		        columns: [
					{
						checkbox: true
					},
					{
						field: 'talkId',
						title: '编号',
					},
					{
						field: 'talkCenter',
						title: '主题'
					},
					{
						field: 'userId',
						title: '工号'
					},
					{
		            	field: 'author',
		            	title: '作者'
		        	},
					{
						field: 'talkTime',
						title: '发帖时间'
					},
					{
						field: 'auditState',
						title: '状态'
					},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		                var actions = [];
						actions.push('<a class="btn btn-success btn-xs ' + seeFlag + '" href="javascript:void(0)" onclick="see(\'' + row.talkId+ '\')"><i class="fa fa-edit"></i>详情</a> ');
						actions.push('<a class="btn btn-success btn-xs ' + agreeFlag + '" href="javascript:void(0)" onclick="agree(\'' + row.talkId+ '\')"><i class="fa fa-plus"></i>通过</a> ');
						actions.push('<a class="btn btn-danger btn-xs ' + rejectFlag + '" href="javascript:void(0)" onclick="reject(\'' + row.talkId+ '\')"><i class="fa fa-remove"></i>拒绝</a> ');
		                return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);
		});

		function see(id) {
			table.set();
			if($.common.isEmpty(id) && table.options.type == table_type.bootstrapTreeTable) {
				var row = $("#" + table.options.id).bootstrapTreeTable('getSelections')[0];
				if ($.common.isEmpty(row)) {
					$.modal.alertWarning("请至少选择一条记录");
					return;
				}
				var url = table.options.updateUrl.replace("{id}", row[table.options.uniqueId]);
				$.modal.open(table.options.modalName + "详情", url);
			} else {
				$.modal.open(table.options.modalName + "详情", $.operate.editUrl(id));
			}
		}


		// 同意
		function agree(id) {
			table.set();
			$.modal.confirm("确定通过该条" + table.options.modalName + "吗？", function() {
				var url = $.common.isEmpty(id) ? table.options.agreeUrl : table.options.agreeUrl.replace("{id}", id);
				if(table.options.type == table_type.bootstrapTreeTable) {
					$.operate.get(url);
				} else {
					var data = { "ids": id };
					$.operate.submit(url, "post", "json", data);
				}
			});
		}

		// 批量同意
		function agreeAll() {
			table.set();
			var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
			if (rows.length == 0) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}
			$.modal.confirm("确认要通过" + rows.length + "条帖子吗?", function() {
				var url = table.options.agreeUrl;
				var data = { "ids": rows.join() };
				$.operate.submit(url, "post", "json", data);
			});
		}

		// 拒绝
		function reject(id) {
			table.set();
			$.modal.confirm("确定拒绝该条" + table.options.modalName + "帖子吗？", function() {
				var url = $.common.isEmpty(id) ? table.options.rejectUrl : table.options.rejectUrl.replace("{id}", id);
				if(table.options.type == table_type.bootstrapTreeTable) {
					$.operate.get(url);
				} else {
					var data = { "ids": id };
					$.operate.submit(url, "post", "json", data);
				}
			});
		}

		// 批量拒绝
		function rejectAll() {
			table.set();
			var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
			if (rows.length == 0) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}
			$.modal.confirm("确认要拒绝" + rows.length + "条帖子吗?", function() {
				var url = table.options.rejectUrl;
				var data = { "ids": rows.join() };
				$.operate.submit(url, "post", "json", data);
			});
		}

	</script>
</body>
</html>